import database
from database import User
from sqlalchemy.sql.expression import and_

def getUser(login):
    session = database.getSession()
    with session.begin(subtransactions=True):
        return session.query(User).filter(User.login == login).one()

def isAuthenticated(login, password):

    session = database.getSession()
    with session.begin():
        return session.query(User) \
            .filter(and_(User.login == login, User.password == password)).count() == 1
